package com.yong.ssj.control.consumer.customer;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yong.ssj.db.dto.customer.CustomerDto;
import com.yong.ssj.db.dto.customer.MaterialDto;
import com.yong.ssj.service.customer.IOrdinaryService;
import com.yong.ssj.vo.customer.RenzhenVo;
import com.yong.ssj.vo.customer.jiashiVo;
import com.yong.ssj.vo.customer.twiceDrVo;
import com.yong.ssj.vo.customer.twiceIdVo;

@Controller
@RequestMapping("/consumer/customer")
public class CustomerControllerph {

	@Resource(name="OrdinaryServiceImpl")
	private IOrdinaryService ordinaryService;

    @RequestMapping("index")  
    public String shouyeList(ModelMap rps,HttpSession session){  //首页界面
    	String customer_id = (String)session.getAttribute("customer_id");
    	List<Map<String, Object>> list = ordinaryService.indexst(customer_id);
    	Map<String, Object> map = list.get(0);
    	session.setAttribute("rz_surplus_money", (Double)map.get("rz_surplus_money"));
    	rps.put("material", list);
        return "consumer/customer/index";   
    }  
    
    @RequestMapping("select")  
    public String xuanString(){  //选择认证版本界面
        return "consumer/customer/select";   
    } 
    
    @RequestMapping("idcard")  
    public String idcardString(){  //认证普通版本界面
        return "consumer/customer/idcard";   
    }  
    
    @RequestMapping("idcard2")  
    public String idcardString2(HttpSession session,ModelMap rps){  //认证普通版本界面
    	String customer_id = (String)session.getAttribute("customer_id");
    	CustomerDto cus = ordinaryService.queryCus(Long.parseLong(customer_id));
    	MaterialDto mat = ordinaryService.chaxun(Long.parseLong(customer_id));
    	rps.put("CustomerDto", cus);
    	rps.put("MaterialDto", mat);
        return "consumer/customer/idcard2";   
    }  
    
    @RequestMapping("idcard_do")  
    @ResponseBody
    public String idcardrzString(HttpSession session,RenzhenVo vo){  //认证普通版本操作
    	String customer_id = (String)session.getAttribute("customer_id");
    	MaterialDto dto = ordinaryService.chaxun(Long.parseLong(customer_id));
    	if(dto==null){
    		int yan = ordinaryService.renzhenPt(vo, customer_id);
            return "1";
    	}else {
			return "0";
		}
    }  
    
    @RequestMapping("idcard_do2")  
    @ResponseBody
    public String idcardrzString2(HttpSession session,twiceIdVo vo){  //二次认证普通版本操作
    	String customer_id = (String)session.getAttribute("customer_id");
    	int yan = ordinaryService.updateTwiceID(vo,Long.parseLong(customer_id));
        return "1";
    }  
    
    @RequestMapping("driving_do2")  
    @ResponseBody
    public String drivingrzString2(HttpSession session,twiceDrVo vo){  //二次认证驾驶版本操作
    	String customer_id = (String)session.getAttribute("customer_id");
    	int yan = ordinaryService.updateTwiceDr(vo,Long.parseLong(customer_id));
        return "1";
    }  
    
    @RequestMapping("driving")  
    public String drivingString(){  //认证驾驶版本界面
        return "consumer/customer/driving";   
    }  

    @RequestMapping("driving2")  
    public String drivingString2(HttpSession session,ModelMap rps){  //认证驾驶版本界面
    	String customer_id = (String)session.getAttribute("customer_id");
    	CustomerDto cus = ordinaryService.queryCus(Long.parseLong(customer_id));
    	MaterialDto mat = ordinaryService.chaxun(Long.parseLong(customer_id));
    	rps.put("CustomerDto", cus);
    	rps.put("MaterialDto", mat);
        return "consumer/customer/driving2";   
    }  
    
    @RequestMapping("driving_do")  
    @ResponseBody
    public String drivingrzString(HttpSession session,jiashiVo vo){  //认证驾驶证版本操作
    	String customer_id = (String)session.getAttribute("customer_id");
    	MaterialDto dto = ordinaryService.chaxun(Long.parseLong(customer_id));
    	if(dto==null){
    		int yan = ordinaryService.jiashiPt(vo, customer_id);
            return "1";
    	}else {
			return "0";
		}
    }

    @RequestMapping("more")  
    public String moreString(){  //更多界面
        return "consumer/customer/more";   
    }  

    @RequestMapping("pinpai")  
    public String pinString(){  //品牌界面
        return "consumer/customer/pinpai";   
    }  

    @RequestMapping("kefu")  
    public String kefuString(){  //咨询客服界面
        return "consumer/customer/kefu";   
    }  

    @RequestMapping("ziliao")  
    public String ziliaoString(HttpSession session,ModelMap rps){  //修改资料界面
    	String customer_id = (String)session.getAttribute("customer_id");
    	CustomerDto dto = ordinaryService.queryCus(Long.parseLong(customer_id));
    	rps.put("CustomerDto", dto);
        return "consumer/customer/ziliao";   
    }  

    @RequestMapping("ziliao_do")  
    public String ziliaodoString(HttpSession session,ModelMap rps,String zfb_code,String wx_code,String address){  //修改资料
    	String customer_id = (String)session.getAttribute("customer_id");
    	int yan = ordinaryService.updateziliao(zfb_code, wx_code, address,Long.parseLong(customer_id));
    	if(yan==1){
    		rps.put("tishi", "修改资料成功！");
    		return "consumer/customer/more";   
    	}else{
    		rps.put("tishi", "修改资料失败！");
    		return "consumer/customer/ziliao";  
    	}
    }  
    

    @RequestMapping("mima_do")  
    public String mimadoString(String customer_password,String password,HttpSession session,ModelMap rps){  //修改密码
    	String customer_id = (String)session.getAttribute("customer_id");
    	CustomerDto dto = ordinaryService.queryCus(Long.parseLong(customer_id));
    	if(dto.getCustomer_password().equals(customer_password)){
    		int yan = ordinaryService.updatePassword(password, Long.parseLong(customer_id));
    		if(yan==1){
    			rps.put("tishi", "密码修改成功!");
        		return "consumer/sys/mima";
    		}else{
    			rps.put("tishi", "密码修改失败!");
        		return "consumer/sys/mima";
    		}
    	}else {
    		rps.put("tishi", "您输入的密码错误!");
    		return "consumer/sys/mima";
		}
    }  
}
